{extend name="base/base" /}
{block name="style"}
<style type="text/css">
.layui-table-cell{
     height: auto!important;
     white-space: normal;
}
a:hover{color:red}
</style>
{/block}
{block name="content"}
  <div class="layui-form-item layui-form-pane">
    <div class="layui-inline">
        <div class="demoTable">
          <button class="layui-btn layui-btn-normal" onclick="add()">新增</button>
        </div>
      </div>
  <table id="table" lay-filter="table"></table> 
</div>
  <script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
  </script>
{/block}
{block name="script"}
<script>
layui.use(['table', 'laydate'], function(){
  var table = layui.table;
  var laydate = layui.laydate;
  table.render({
    elem: '#table'
    ,height: 'full-200'
    ,url: '/admin/community/slideshowList/' //数据接口
    ,limit:10
    ,page: true //开启分页
    ,id:'reload'
    ,cols: [[ //表头
      {field:'pic', title: '轮播图', width: 150,templet: function(d){
        return '<img src="'+d.pic+'" style="width:100px;height:100px">'
      }}
      ,{title:'操作', toolbar: '#barDemo', width:200}
    ]]
  }); 
  //监听工具条
  table.on('tool(table)', function(obj){
    var data = obj.data;
    if(obj.event === 'del'){
      layer.confirm('确定删除？', function(index){
        $.ajax({
          url:"{:url('admin/community/delSlideshow')}?id="+data.id,
          type:'GET',
          success:function(ret){
            if(ret.code == 0) {
              layer.msg('删除成功');
              obj.del();
            } else {
              layer.msg('删除失败');
            }
          }
        });
      });
    }
  });
});

function add(){
  layer.open({
        type: 2 ,
        title: '新增',   //标题
        area: ['800px', '600px'],   //宽高
        shade: 0.4,   //遮罩透明度
        content: '/admin/community/addSlideshow',//支持获取DOM元素
        // end:function(){
        //   $(".layui-laypage-btn")[0].click();
        // }
        });
}
</script>
{/block}
